# 盒子的位置关乎到机械臂取盒子时，轨道应该移动到的位置

from singleton import singleton
import modbus_tk.defines as cst
from ModbusManager import ModbusManager


@singleton
class Box(object):
    dev_id = 2
    temp = 0
    box_lines = 8
    lines = []

    def is_empty(self):
        ret = ModbusManager().execute(self.dev_id, cst.READ_HOLDING_REGISTERS, 0x7002, self.box_lines)
        self.lines = ret
        for stat in ret:
            if stat > 0:
                return False

        return True

    def get_pos(self):
        return self.lines.index(1)
